package com.ruoyi.project.user.appUser.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.constant.BusinessType;
import com.ruoyi.project.user.appUser.domain.AppUser;
import com.ruoyi.project.user.appUser.service.IAppUserService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * app用户 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-08-31
 */
@Controller
@RequestMapping("/user/appUser")
public class AppUserController extends BaseController
{
    private String prefix = "user/appUser";
	
	@Autowired
	private IAppUserService appUserService;
	
	@RequiresPermissions("user:appUser:view")
	@GetMapping()
	public String appUser()
	{
	    return prefix + "/appUser";
	}
	
	/**
	 * 查询app用户列表
	 */
	@RequiresPermissions("user:appUser:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(AppUser appUser)
	{
		startPage();
        List<AppUser> list = appUserService.selectAppUserList(appUser);
		return getDataTable(list);
	}
	
	/**
	 * 新增app用户
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存app用户
	 */
	@RequiresPermissions("user:appUser:add")
	@Log(title = "app用户", action = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(AppUser appUser)
	{		
		return toAjax(appUserService.insertAppUser(appUser));
	}

	/**
	 * 修改app用户
	 */
	@GetMapping("/edit/{appUserId}")
	public String edit(@PathVariable("appUserId") String appUserId, ModelMap mmap)
	{
		AppUser appUser = appUserService.selectAppUserById(appUserId);
		mmap.put("appUser", appUser);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存app用户
	 */
	@RequiresPermissions("user:appUser:edit")
	@Log(title = "app用户", action = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(AppUser appUser)
	{		
		return toAjax(appUserService.updateAppUser(appUser));
	}
	
	/**
	 * 删除app用户
	 */
	@RequiresPermissions("user:appUser:remove")
	@Log(title = "app用户", action = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(appUserService.deleteAppUserByIds(ids));
	}
	
}
